/*******************날짜 확인***********************/
function formDateChk(startDt, endDt){
	
	startDt  = startDt.split("-").join("");
	endDt    = endDt.split("-").join("");

	
	if( startDt != "" ){
		if(!isValidDate(startDt,"Start date")){
			return false;	
		}
	}
	if( endDt != "" ){
		if(!isValidDate(endDt,"End date")){
			return false;	
		}
	}
	if( startDt != "" && endDt != "" ){

	    if(startDt > endDt){
	        alert("Start date can not be End date than the termination date.");
	        return false;
	    }
	}
	
   return true;
 }

function isValidDate(val,msg){

	var dateTmp = val.split("-").join("");
	
	if(isNaN(dateTmp)){
		return false;
	}

	if(dateTmp !=0 && dateTmp.length == 8){

		var tmpYear = dateTmp.substr(0, 4);
		var tmpMonth = dateTmp.substr(4, 2);
		var tmpDay = dateTmp.substr(6, 2);

		var tmpM = parseInt(tmpMonth, 10)-1;
		var tmpD = parseInt(tmpDay, 10);

		var tmpEndDay = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

		if((tmpYear%4 == 0 && tmpYear%100 != 0) || tmpYear%400 == 0){
			tmpEndDay[1] = 29;
		}
		if((tmpD >=1 && tmpD <= tmpEndDay[tmpM])){
			return true;
		}else{
			alert(msg+": Date is not in the correct format. \n ex) YYYYMMDD or YYYY-MM-DD");
			return false;
		}
		return (tmpD >=1 && tmpD <= tmpEndDay[tmpM]);
	}else{
		alert(msg+": Date is not in the correct format. \n ex) YYYYMMDD or YYYY-MM-DD");
		return false;
	}
	return true;
}

/*******************테이블 ROW CNT***********************/
// tableRowCnt("tmpTable" , "name")   또는 tableRowCnt("tmpTable" , "id") 
function tableRowCnt(table , selectorType){
	var tableRowCnt;
	
	if( selectorType.toUpperCase() == "NAME" ){
		tableRowCnt = $("table[name='"+table+"']").length;
	}else if( selectorType.toUpperCase() == "ID" ){
		tableRowCnt = $("#"+table).length;
	}
	return tableRowCnt;
}


//숫자만 입력 and  엔터키 설정 checkEnterKeyDown(e)  checkEnterKeyDown(e,'search()')
function checkEnterKeyDown(e, functionName) {
	
	if (window.event) { // IE
		e = window.event;
	}
	if (typeof (e.keyCode) == 'number') {
		//DOM
		e = e.keyCode;
	} else if (typeof (e.which) == 'number') {
		//NS 4 compatible
		e = e.which;
	} else if (typeof (e.charCode) == 'number') {
		//also NS 6+, Mozilla 0.9+
		e = e.charCode;
	} else {
		//total failure, we have no way of obtaining the key code
		return;
	}

	if (e == 13) {
		eval(functionName);
		return false;
	}
}



//onkeydown="onlyNum()"    (숫자만 입력시 style="IME-mode:disabled" 같이 사용 ) 
function onlyNum(e) {
	if (window.event) { // IE
		e = window.event;
	}
	if (typeof (e.keyCode) == "number") {
		//DOM
		e = e.keyCode;
	} else if (typeof (e.which) == "number") {
		//NS 4 compatible
		e = e.which;
	} else if (typeof (e.charCode) == "number") {
		//also NS 6+, Mozilla 0.9+
		e = e.charCode;
	} else {
		//total failure, we have no way of obtaining the key code
		return;
	}

	if(e == 8 || e == 9 || e == 37 || e == 39 || e == 190 
			|| (e >= 96 && e<= 105)	) return;		
	
	if((e != 45) && (e < 45) || (e > 57)) {
		event.returnValue = false;
	}
};



//onkeydown="onlyNum()"    (숫자만 입력시 style="IME-mode:disabled" 같이 사용 ) 
function onlyNum2(e) {
	if (window.event) { // IE
		e = window.event;
	}
	if (typeof (e.keyCode) == "number") {
		//DOM
		e = e.keyCode;
	} else if (typeof (e.which) == "number") {
		//NS 4 compatible
		e = e.which;
	} else if (typeof (e.charCode) == "number") {
		//also NS 6+, Mozilla 0.9+
		e = e.charCode;
	} else {
		//total failure, we have no way of obtaining the key code
		return;
	}
	if(e == 8 || e == 9 || e == 37 || e == 39 || e == 107 || e == 109 || e == 187 || e == 189
			|| (e >= 96 && e<= 105)	) return;		
	
	if((e != 45) && (e < 45) || (e > 57)) {
		event.returnValue = false;
	}
};


function engOnly(e){	

 var code = (window.event) ? event.keyCode : e.which; //IE : FF - Chrome both
 if ( (code >= 65 && code <= 90) || code == 8 || code == 9
      || (event.shiftKey == true && code == 186)
      || (event.shiftKey == false && code == 190)
      || (event.shiftKey == false && code == 191)
      || (event.shiftKey == false && code == 48)
      || (event.shiftKey == false && code == 49)
      || (event.shiftKey == false && code == 50)
      || (event.shiftKey == false && code == 51)
      || (event.shiftKey == false && code == 52)
      || (event.shiftKey == false && code == 53)
      || (event.shiftKey == false && code == 54)
      || (event.shiftKey == false && code == 55)
      || (event.shiftKey == false && code == 56)
      || (event.shiftKey == false && code == 57)
      && (code != 229) ){
 	
 }else{
 	if(navigator.appName != "Netscape"){ //for not returning keycode value
         event.returnValue = false;  //IE ,  - Chrome both
     }else{
         e.preventDefault(); //FF ,  - Chrome both
 	}
 }
};


function lpad(str,len,addStr) {
    var result = str+"";

    var templen   = len - result.length;

    for (var i = 0; i < templen; i++){
          result = addStr + result;
    }
    return result;
};